using System;
using System.Collections.Generic;

namespace QntPlatform.Strategy.Utility
{
    public class CmdFun
    {
       static IStrParse StrParse=new StrParse();
        public static KeyValuePair<string, string> GetCmdKV(string cmdStr)
        {
            //
            var cmdArr = cmdStr.Split(':', 2);
            string cmdVal = null;
            var cmdName = cmdArr[0];
            if (cmdArr.Length < 2)
            {
                if (cmdStr.StartsWith('{') || cmdStr.EndsWith('}'))
                {
                    var dic = StrParse.Parse<Dictionary<string, object>>(cmdStr);
                    if (dic.TryGetValue("cmdName", out var strName))
                    {
                        return new KeyValuePair<string, string>(strName + "", cmdStr);
                    }
                }
                return new KeyValuePair<string, string>(cmdName, cmdVal);
            }
            // var cr = new CsvReader(new StringReader(cmdStr),'~','*') ;
            //var list= cr.ReadCsv();


            cmdVal = cmdArr[1];
            return new KeyValuePair<string, string>(cmdName, cmdVal);
        }
    }
}
